# Maintainer: Pellegrino Prevete <pellegrinoprevete@gmail.com>

_realname=libhandy
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.13
pkgrel=1
pkgdesc="A library full of GTK+ widgets for mobile phones (mingw-w64)"
url="https://source.puri.sm/Librem5/libhandy"
license=("LGPL2.1")
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
options=('strip' 'staticlibs' '!debug')
source=("https://source.puri.sm/Librem5/libhandy/-/archive/v${pkgver}/libhandy-v${pkgver}.tar.bz2"
        001-fix-types.patch)
sha256sums=('507f92e173a6ab9c07f612d2758de434f1feeb72ca4a9dd7de16d9a2b533d60b'
            'd6aeaf23c740622f791679a5d9638b8da90ae2d04f71ecb7189086cd7aaafacf')

prepare() {
  cd libhandy-v${pkgver}
  patch -p1 -i ${srcdir}/001-fix-types.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  ${MINGW_PREFIX}/bin/meson \
    --buildtype=plain \
    -Dexamples=false \
    -Dgtk_doc=false \
    -Dglade_catalog=disabled \
    ../"libhandy-v${pkgver}"

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}"/build-${CARCH}
  DESTDIR="${pkgdir}${MINGW_PREFIX}" ${MINGW_PREFIX}/bin/ninja install
  
  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"

  for pcfile in  "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|${_PRE_WIN}|${MINGW_PREFIX}|g" -i "${pcfile}"
  done
}
